package com.parking.app;

import java.util.ArrayList;
import java.util.Date;

import com.parking.R;
import com.parking.model.Park;
import com.parking.model.TypeEnum;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;

@SuppressLint("InflateParams") 
public class SearchActivity extends Activity implements OnItemClickListener{

	private ListView park_list;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_search);
		
		ActionBar actionBar = getActionBar();               
        actionBar.setCustomView(R.layout.actionbar_top);
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_SHOW_CUSTOM); //show it
        
        park_list = (ListView) findViewById(R.id.park_list);
        park_list.setItemsCanFocus(false);
        park_list.setFocusable(true);
        park_list.setFocusableInTouchMode(true);
        park_list.setClickable(true);
        park_list.setOnItemClickListener((OnItemClickListener) this);
        
        ArrayList<Park> park_array = new ArrayList<Park>();              
        Park p = new Park();       
        p.setStreet("Areolino de Abreu");
        p.setLatitude(000.000);
        p.setDate(new Date());
        p.setType(TypeEnum.STREET);                
        park_array.add(p);
        
        p = new Park();
        p.setStreet("Paissandu");
        p.setLatitude(111.111);
        p.setDate(new Date());
        p.setType(TypeEnum.PUBLIC);
        park_array.add(p);
                
        ParkAdapter adapter = new ParkAdapter(this, R.layout.parkadapter, park_array);
        park_list.setAdapter(adapter);
        
        
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        LayoutInflater inflater = this.getLayoutInflater();
                               
        builder.setTitle(R.string.action_changue_distance);
        builder.setView(inflater.inflate(R.layout.dialog_order, null))
        .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                
            }
        })
        .setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                
            }
        });      
        final AlertDialog dialog_order = builder.create();
       
        TextView order = (TextView) findViewById(R.id.action_order_list);
        order.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				dialog_order.show();
			}
		});
        
        builder.setTitle(R.string.action_preferences_list);
        builder.setView(inflater.inflate(R.layout.dialog_preferences, null))
        .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                
            }
        })
        .setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                
            }
        });      
        final AlertDialog dialog_preferences = builder.create();
       
        TextView preferences = (TextView) findViewById(R.id.action_preferences_list);
        preferences.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				dialog_preferences.show();
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		
	}
}
